<!-- 机构列表 -->
<template>
  <div class="web">
    <!-- 搜索 -->
    <el-card>
      <el-form ref="ruleFormRef" :inline="true" class="demo-form-inline" :model="params">
        <el-form-item label="机构名称：">
          <el-input v-model="params.key" clearable placeholder="请输入" />
        </el-form-item>
        <el-form-item label="管理姓名：">
          <el-input v-model="params.name" clearable placeholder="请输入" />
        </el-form-item>

        <el-form-item>
          <el-button type="primary" :icon="Search" @click="search">查询</el-button>
          <el-button :icon="Refresh" @click="resetForm(ruleFormRef)">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <!-- 列表 -->
    <el-card class="card">
      <ELTable v-bind="tableConfig" ref="customerTable">
        <template #btns="{ deleteAll }">
          <el-button type="primary" @click="add">
            <el-icon class="icon">
              <Plus />
            </el-icon>
            新增
          </el-button>

          <el-button :icon="Delete" type="danger" @click="deleteAll">批量删除</el-button>
        </template>

        <template #operate="{ scope, deleteHandle }">
          <el-button type="primary" :icon="Edit" text @click="uploadEdit(scope.row.id)">
            编辑
          </el-button>

          <el-button type="danger" :icon="Delete" text @click="deleteHandle(scope.row.id)">
            删除
          </el-button>
        </template>
      </ELTable>
    </el-card>
  </div>
</template>
<script setup lang="ts">
import { reactive, ref } from "vue";
import { useRouter } from "vue-router";
import ELTable, { TableData } from "@/components/ELTable.vue";
import { CompanyList } from "@/api/company/type";
import { delCompany, delMany, getCompanyList } from "@/api/company/Company";
import AddCompany from "./AddCompany.vue";

import { Delete, Edit, Message, Document, Search, Refresh } from "@element-plus/icons-vue";
import type { FormInstance } from "element-plus";
import { ElMessage, ElMessageBox } from "element-plus";

import router from "@/router";

const ruleFormRef = ref<FormInstance>();

const input = ref("");
const customerTable = ref();
const tableConfig = reactive<TableData>({
  loadData: getCompanyList,
  delete: delCompany,
  deleteAll: delMany,

  columns: [
    {
      prop: "id",
      label: "序号",
    },
    {
      prop: "name",
      label: "机构名称",
    },
    {
      prop: "address",
      label: "区域",
    },
    {
      prop: "adminUserName",
      label: "管理员姓名",
    },
    {
      prop: "telephone",
      label: "联系电话",
    },
    {
      prop: "adminId",
      label: "管理员账号",
    },
    {
      prop: "adminPwd",
      label: "管理员密码",
    },
    {
      prop: "operate",
      label: "操作",
      slot: true,
    },
  ],
});

//搜索参数
const params = reactive<CompanyList>({
  page: 1,
  pageSize: 10,
  name: "",
  key: "",
});

// 查询
const search = () => {
  customerTable.value.getData(params);
  // console.log("查询", params);
};
//重置
const resetForm = (formEl: FormInstance | undefined) => {
  if (!formEl) return;
  formEl.resetFields();
};

// 新增
const add = () => {
  router.push("../company/add");
};
// 编辑
const uploadEdit = (id: number) => {
  console.log(id);
  router.push({ path: "../company/add", query: { id: id } });
};
</script>
<style scoped>
.web {
  margin: 10px;
}

.web_top {
  display: flex;

  /* justify-content:space-betwee; */
}

.web_top > div {
  margin-left: 32px;
}

.card {
  margin-top: 10px;
}
</style>
